// 使dom在容器内可拖拽
export function dragable(dom, mainContainer) {
  dom.addEventListener('mousedown', e => {
    e.preventDefault()

    const target = e.target
    if (!target) true
    target.isMouseDown = true
  })

  mainContainer.addEventListener('mousemove', e => {
    e.stopPropagation()

    const { movementX, movementY } = e
    const target = dom
    if (target.isMouseDown) {
      target.style.left = target.offsetLeft + movementX + 'px'
      target.style.top = target.offsetTop + movementY + 'px'
    }
  })

  dom.addEventListener('mouseup', e => {
    const target = e.target
    target.isMouseDown = false
  })
}
